<?php
namespace app\controller;

use app\component\httpReferer\HttpRefererComponent;
use app\service\TemplateService;

/**
 * 控制器
 * */
class Controller {
    /**
     * 
     * @param $title 标题
     * @param $message 内容
     * @param $backUrl 回跳地址
     * */
    public function error($title = '操作失败', $message = '', $backUrl = null) {
        $this->successOrError(false, $title, $message, $backUrl);
    }

    /**
     * 
     * @param $title 标题
     * @param $message 内容
     * @param $backUrl 回跳地址
     * */
    public function success($title = '操作成功', $message = '', $backUrl = null) {
        if (is_null($backUrl)) {
            $backUrl = HttpRefererComponent::getValue();
        }
        $this->successOrError(true, $title, $message, $backUrl);
    }

    public function successOrError($success, $title, $message, $backUrl) {
        echo TemplateService::render('view/successOrError.html', [
            'success' => $success,
            'title' => $title,
            'message' => $message,
            'backUrl' => $backUrl
        ]);
        exit();
    }
}